package course;
import java.util.ArrayList;
import java.util.List;
public class TestCourse {
    private List<Teacher> teachers;
    private List<Student> students;
    private List<Course> courses;
    private int courseIdCounter;  // 用于生成唯一课程ID

    public TestCourse() {
        teachers = new ArrayList<>();
        students = new ArrayList<>();
        courses = new ArrayList<>();
        courseIdCounter = 1;  // 课程ID从1开始
    }

    // 创建教师
    public Teacher createTeacher(int teacherId, String name, String gender, String phoneNumber) {
        Teacher teacher = new Teacher(teacherId, name, gender, phoneNumber);
        teachers.add(teacher);
        return teacher;
    }

    // 为教师添加课程
    public Course addCourseToTeacher(Teacher teacher, String courseName, String location, String time, double credits) {
        Course course = new Course(courseIdCounter++, courseName, location, time, credits);
        teacher.addCourse(course);
        courses.add(course);
        return course;
    }

    // 创建学生
    public Student createStudent(int studentId, String name, String gender, int grade, String major) {
        Student student = new Student(studentId, name, gender, grade, major);
        students.add(student);
        return student;
    }

    public void runSimulation() {
        // 1. 创建3位教师
        Teacher teacher1 = createTeacher(1, "张老师", "男", "13800138001");
        Teacher teacher2 = createTeacher(2, "李老师", "女", "13900139002");
        Teacher teacher3 = createTeacher(3, "王老师", "男", "13700137003");

        // 2. 为教师添加课程（分别为1、2、3门）
        // 教师1：1门课程
        Course course1 = addCourseToTeacher(teacher1, "Java编程基础", "教学楼A101", "周一8:00-9:40", 3.0);

        // 教师2：2门课程
        Course course2 = addCourseToTeacher(teacher2, "数据结构", "教学楼B201", "周二10:00-11:40", 4.0);
        Course course3 = addCourseToTeacher(teacher2, "算法分析", "教学楼B202", "周四10:00-11:40", 3.5);

        // 教师3：3门课程
        Course course4 = addCourseToTeacher(teacher3, "计算机网络", "教学楼C301", "周三19:00-20:35", 2.0);
        Course course5 = addCourseToTeacher(teacher3, "操作系统", "教学楼C302", "周五15:30-17:10", 2.5);
        Course course6 = addCourseToTeacher(teacher3, "数据库原理", "教学楼C303", "周三13:30-15:10", 3.5);

        // 3. 展示所有教师开设的课程
        System.out.println("===== 教师开课信息 =====");
        teacher1.openCourses();
        teacher2.openCourses();
        teacher3.openCourses();

        // 4. 创建3位学生
        Student student1 = createStudent(2001, "小明", "男", 2, "物联网");
        Student student2 = createStudent(3002, "小红", "女", 3, "数据科学与大数据技术");
        Student student3 = createStudent(1003, "小刚", "男", 1, "人工智能");

        // 5. 学生选课
        System.out.println("\n===== 学生选课过程 =====");
        // 学生1选课
        student1.selectCourse(course1);  // Java编程基础
        student1.selectCourse(course2);  // 数据结构
        student1.selectCourse(course4);  // 计算机网络

        // 学生2选课
        student2.selectCourse(course2);  // 数据结构
        student2.selectCourse(course3);  // 算法分析
        student2.selectCourse(course5);  // 操作系统
        student2.selectCourse(course6);  // 数据库原理

        // 学生3选课
        student3.selectCourse(course1);  // Java编程基础
        student3.selectCourse(course4);  // 计算机网络

        // 6. 打印学生课表
        System.out.println("\n===== 学生课表信息 =====");
        student1.printTimetable();
        student2.printTimetable();
        student3.printTimetable();

        // 7. 学生退课示例
        System.out.println("\n===== 学生退课操作 =====");
        student2.dropCourse(course5);  // 小红退选操作系统

        // 8. 打印退课后的课表
        System.out.println("\n===== 退课后的课表 =====");
        student2.printTimetable();
    }

    public static void main(String[] args) {
        TestCourse test = new TestCourse();
        test.runSimulation();
    }
}
